<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

class CourseResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => (int)$this->id,
            'name' => (string)$this->name,
            'category_name' => (string)$this->category_name,
            'category_id' => (int)$this->category_id,
            'grade_name' => (string)$this->grade_name,
            'grade_id' => (int)$this->grade_id,
            'synopsis' => (string)$this->synopsis,
            'recommend' => (boolean)$this->recommend,
            'image_path' => (string)$this->image_path,
            'speaker_id' => (integer)$this->speaker_id,
            'speaker_name' => (string)$this->speaker_name,
            'lessons' => LessonResource::collection($this->whenLoaded('lessons'))
        ];
    }
}
